home *** CD-ROM | disk | FTP | other *** search
- Path: cville-srv.wam.umd.edu!leungyl
- From: leungyl@wam.umd.edu (David Leung)
- Newsgroups: comp.lang.c++
- Subject: Need help in C
- Date: 24 Jan 1996 05:45:45 GMT
- Organization: University of Maryland College Park
- Message-ID: <4e4h29$3f2@cville-srv.wam.umd.edu>
- NNTP-Posting-Host: rac1.wam.umd.edu
- X-Newsreader: TIN [version 1.2 PL0]
-
- I am studying C/C++ and I arrived at a problem that I am stuck with.
- I think it is easy for expericenced programmers, if you can help me
- please email me at leungyl@wam.umd.edu
-
- this is the problem
-
- input a five digit number
-
- then, separate the five digits into 5 separate numbers and evaluate them
- independently. Basically, cut the number into five pieces. This is what
- I wrote.....
-
- cout << "Enter a five digit number: ";
-
- cin >> input;
-
-
-
- digi1 = input / 10000;
-
- digi2 = input / 1000 - digi1 * 10;
-
- digi3 = input / 100 - digi1 * 100 - digi2 * 10;
-
- digi4 = input / 10 - digi1 * 1000 - digi2 * 100 - digi3 * 10;
-
- digi5 = input - digi1 * 10000 - digi2 * 1000 - digi3 * 100 - digi4 * 10;
-
-
-
- cout << input << endl;
-
- cout << digi1 << endl;
-
- cout << digi2 << endl;
-
- cout << digi3 << endl;
-
- cout << digi4 << endl;
-
- cout << digi5 << endl;
-
-
-
-
-
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- the problem is, it work for some numbers, but for others it doesn't work.
- Why? Can somebody help me??Thanks very much.
-
-
- Regards,
-
-
- David
-
-